﻿CREATE PROCEDURE ProductReview_Delete
@productReviewId int
AS
	SET NOCOUNT ON
		delete from ProductReviews where ProductReviewId = @productReviewId
		
		declare @averageRating float
		declare @productId int
		select @productId = ProductId from ProductReviews where ProductReviewId = @productReviewId
	select @averageRating = avg (Rating) from ProductReviews where ProductId = @productId
	
	update Products set
		Rating = @averageRating
	where ProductId = @productId
	RETURN


